package com.SmartCare.controller.manager;


import com.SmartCare.common.Result;
import com.SmartCare.pojo.medicine.MedicationList;
import com.SmartCare.service.medicine.MedicationListService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前端控制器
 */
@RestController
@RequestMapping("/medication-list")
public class MedicationListController {

    @Resource
    MedicationListService medicationListService;

    //获取所有分组后的药单信息
    @GetMapping("/get-all")
    public Result getAll(@RequestParam String careHomeName, @RequestParam String keyword) {
        return medicationListService.getAll(careHomeName, keyword);
    }

    //添加药单项
    @PostMapping("/add")
    public Result add(@RequestBody MedicationList medicationList) {
        return medicationListService.addOption(medicationList);
    }

    //根据id更新药单项
    @PutMapping("/update")
    public Result update(@RequestBody MedicationList medicationList) {
        return medicationListService.updateOption(medicationList);
    }

    //根据id删除药单项
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Long id) {
        return medicationListService.delete(id);
    }

    //根据药单编号删除药单项
    @DeleteMapping("/delete-batch")
    public Result deleteBatch(@RequestParam Long listNum) {
        return medicationListService.deleteBatch(listNum);
    }

    //根据老人id删除药单项
    @DeleteMapping("/delete-elder")
    public Result deleteByElderId(@RequestParam Long elderId){
        return medicationListService.deleteByElder(elderId);
    }
}

